import { useState, useRef } from 'react';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { Button, Modal, Form } from 'antd';

import { getSmsList } from '@/services/api/message';
import dayjs from 'dayjs';
// import styles from './index.less';

const MessageRecordPage = () => {
  const actionRef = useRef();

  const columns = [
    {
      title: '用户id',
      dataIndex: 'userID',
      hideInSearch: true,
    },
    {
      title: '用户名',
      dataIndex: 'username',
    },
    {
      title: '号码',
      dataIndex: 'phone',
      hideInSearch: true,
      render: (t, row) => row?.User?.phone,
    },
    // {
    //   title: '条数',
    //   dataIndex: 'name1',
    //   hideInSearch: true,
    //   render: (t, row) => row?.User?.num,
    // },
    {
      title: '内容',
      width: 200,
      dataIndex: 'content',
      hideInSearch: true,
    },
    {
      title: '发送状态',
      dataIndex: 'sendStatus',
      initialValue: '-1',
      valueEnum: {
        [-1]: { text: '全部', status: 'Default' },
        1: {
          text: '成功',
          status: 'Success',
        },

        0: {
          text: '失败',
          status: 'Error',
        },
      },
    },
    {
      title: '发送时间',
      dataIndex: 'createTime',
      valueType: 'dateTimeRange',
      search: {
        transform: (value) => ({ createdStar: value[0], createdEnd: value[1] }),
      },
      render: (t, row) => {
        console.log(t, row, '==');
        return dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss');
      },
    },
    {
      title: '到达状态',
      dataIndex: 'arrivalStatus',
      hideInSearch: true,
      valueEnum: {
        [-1]: { text: '全部', status: 'Default' },
        0: { text: '未知', status: 'Default' },
        1: {
          text: '到达成功',
          status: 'Success',
        },

        2: {
          text: '到达失败',
          status: 'Error',
        },
      },
    },
  ];
  return (
    <PageContainer ghost>
      <ProTable
        // headerTitle="查询表格"
        actionRef={actionRef}
        params={{ isWeb: true }}
        rowKey="id"
        search={{
          labelWidth: 120,
        }}
        request={async (params) => {
          const { current, pageSize, sendStatus, ...leftParams } = params;

          const { data, code } = await getSmsList({
            ...leftParams,
            status: sendStatus,
            page: current,
            pageSize,
          });
          return {
            data: data?.list || [],
            success: code === 0,
            total: data?.total,
          };
        }}
        columns={columns}
      />
    </PageContainer>
  );
};

export default MessageRecordPage;
